package view
{
	import com.bit101.components.ColorRadioBtn;
	import com.bit101.components.HBox;
	import com.liu.load.LoadInfo;
	import com.liu.load.LoadManager;
	
	import events.ColorEvent;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class ColorChoose extends Sprite
	{
		private var hbox:HBox;
		[Embed(source="assets/tab/selectColor.png")]
		private var cls:Class;
		public function ColorChoose()
		{
			hbox = new HBox(this,50);
			this.x = 625;
			this.y = 265;
			initTxt();
		}
		private function initTxt():void{
			var txt:TextField = new TextField();
			txt.width = 60;
			txt.height = 25;
			txt.selectable = false;
			txt.htmlText = "<font color='#666666' size='16'>颜色</font>";
			this.addChild(txt);
		}
		public function set source(value:XML):void{
			hbox.removeAllChild();
			var btn:ColorRadioBtn
			for each(var xml:XML in value.color[0].color){
				var color:uint = parseInt(xml.@value,16);
				btn = new ColorRadioBtn();
				btn.color = String(xml.@value);
				btn.SetColor(color,cls);
				hbox.addChild(btn);
				btn.addEventListener(MouseEvent.CLICK,onClick);
			}
			btn = hbox.getChildAt(0) as ColorRadioBtn;
			var evt:ColorEvent = new ColorEvent(ColorEvent.COLOREVENT);
			evt.color = btn.color;
			this.dispatchEvent(evt);
			btn.selected = true;
		}
		private function onClick(event:MouseEvent):void{
			var evt:ColorEvent = new ColorEvent(ColorEvent.COLOREVENT);
			evt.color = ColorRadioBtn(event.target).color;
			this.dispatchEvent(evt);
		}
	}
}